<?php header("Content-Type:text/html;   charset=utf-8"); ?>
<script type="text/javascript">
	$(function(){
		$("#btnSubmitNewGroup").bind("click",submit);	
		$("#txtUserGroupNewGroup").bind("blur",checkUserGroup);
		loadUserGroupNewGroup();
	});		
	function submit(){
		if(checkUserGroup()==false)
			return;
		var name = $("#txtUserGroupNewGroup").val();
		var id = $("#hdidNewGroup").val();
		var params = {
					id:id,
					name:name
				};
		$.ajax({
			type:"post",
			url:"admin.php/manage/addUserGroup",
			dataType:"json",
			data:params,
			async:false,
			success:function(data){
				if(data.ReturnCode==1){
					parent.loadUserGroup();
					alert("操作成功");
					$("#txtUserGroupNewGroup").val('');					
					if(id!=0){
						$("#btnCloseNewGroup").trigger("click");
					}
				}
			}
		});
	}
	function loadUserGroupNewGroup(){
		var id = $("#hdidNewGroup").val();
		if(id==0)
			return;
		var params = {id:id};
		$.ajax({
			type:"post",
			url:"admin.php/manage/getUserGroupById",
			dataType:"json",
			data:params,
			success:function(data){
				$("#txtUserGroupNewGroup").val(data.name);
			}
		});
	}
	function checkUserGroup(){
		var name = $("#txtUserGroupNewGroup").val();
		var id = $("#hdidNewGroup").val();
		if(IsEmpty(name)){
			SetError("txtUserGroupNewGroup","用户组名称不能为空");
			return false;
		}
		var len = name.length;
		if(len>20){
			SetError("txtUserGroupNewGroup","用户组名最多20个字符");
			return false;
		}
		var params = {
					id:id,
					name:name
				};
		var isok = true;
		$.ajax({
			type:"post",
			url:"admin.php/manage/checkExistsUserGroupName",
			dataType:"json",
			data:params,
			async:false,
			success:function(data){
				if(data.ReturnCode!=1){
					SetError("txtUserGroupNewGroup","该用户组名称已存在");
					isok=false;
				}
			}
		});
		if(isok==false)
			return false;
		ClearError("txtUserGroupNewGroup");
		//SetOK("txtUserGroupNewGroup");
		return true;
	}
</script>
<div class="pageContent">
	<form class="pageForm required-validate">
		
		<div class="pageFormContent" style="float: left; width: 500px;"
			layoutH="56">
			<table class="tableNewUser">
				
				<tr>
					<td>用户组名称：</td>
					<td><input type="text" id="txtUserGroupNewGroup"></td>
				</tr>
				
				<tr>
					<td colspan="2" style="line-height: 60px">&nbsp;</td>
				</tr>
			</table>
			<input type="hidden" id="hdidNewGroup"
				value="<?php if(isset($_GET["id"])) print $_GET["id"]; else print 0;?>">

			<div class="buttonActive" style="width: 120px; margin-left: 80px;">
				<div class="buttonContent">
					<button id="btnSubmitNewGroup" type="button" style="width: 80px">提 交</button>
				</div>
			</div>

			<div class="button">
				<div class="buttonContent">
					<button id="btnCloseNewGroup" type="button" class="close"
						style="width: 80px">取 消</button>
				</div>
			</div>
		</div>		
	</form>
</div>
